Class LogUtil


  • public class LogUtil
    extends java.lang.Object
    Logging utility for documenting the state of the program. This simple custom built logging utility outputs to a file the steps involved in the program. It may also be configured to output to the terminal as well.
    Version:
    3.1 May 28, 2015
    Author:
    Charles Allen Schultz II
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.io.BufferedWriter bW
      The BufferedWriter used to log to a file.
      private java.util.HashMap<LogType,​java.lang.Boolean> fileLogs
      The HashMap used for determining which of the logging outputs are logged to a file.
      private boolean logToFile
      The value representing if logging to a file is enabled.
      private boolean logToTerminal
      The value representing if logging to the terminal is enabled.
      private LogLevel maxGranularity
      The maximum granularity of the logging utility.
      static java.lang.String path
      TEST
      private java.util.HashMap<LogType,​java.lang.Boolean> terminalLogs
      The HashMap used for determining which of the logging outputs are logged to the terminal.
    • Constructor Summary

      Constructors 
      Constructor Description
      LogUtil​(LogLevel maxGranularity, boolean logToTerminal)
      Constructs the logging utility.
      LogUtil​(LogLevel maxGranularity, boolean[] fileLogs, boolean[] terminalLogs)
      Constructs the logging utility.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void destroy()
      Destroys all logging functionality of the log engine.
      void destroyLogToFile()
      Destroys the Logging to File functionality of the log engine.
      void destroyLogToTerminal()
      Destroys the Logging to Terminal functionality of the log engine.
      private void log​(LogType type, LogLevel granularity, java.lang.String detail)
      Used to log data.
      void logAlgo​(LogLevel level, java.lang.String detail)
      Logs an ALGO message.
      void logError​(LogLevel level, java.lang.String detail)
      Logs an ERROR message.
      void logGraph​(LogLevel level, java.lang.String detail)
      Logs a GRPH message.
      void logInfo​(LogLevel level, java.lang.String detail)
      Logs an INFO message.
      private void reportProblem​(java.lang.String problem, java.lang.String solution)
      Used to report problems with the logging engine to the terminal.
      private void setFileLogs​(boolean[] fileLogs)
      Sets the FileLogs HashMap for selective logging to the file.
      private void setTerminalLogs​(boolean[] terminalLogs)
      Sets the TerminalLogs HashMap for selective terminal logging.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • path

        public static java.lang.String path
        TEST
      • bW

        private final java.io.BufferedWriter bW
        The BufferedWriter used to log to a file.
      • logToFile

        private boolean logToFile
        The value representing if logging to a file is enabled. Defaults to true and is only set to false due to a malfunction in the BufferedWriter.
      • logToTerminal

        private boolean logToTerminal
        The value representing if logging to the terminal is enabled. Defaults to true.
      • maxGranularity

        private final LogLevel maxGranularity
        The maximum granularity of the logging utility. Anything greater will be ignored.
      • terminalLogs

        private final java.util.HashMap<LogType,​java.lang.Boolean> terminalLogs
        The HashMap used for determining which of the logging outputs are logged to the terminal.
      • fileLogs

        private final java.util.HashMap<LogType,​java.lang.Boolean> fileLogs
        The HashMap used for determining which of the logging outputs are logged to a file.
    • Constructor Detail

      • LogUtil

        public LogUtil​(LogLevel maxGranularity,
                       boolean[] fileLogs,
                       boolean[] terminalLogs)
        Constructs the logging utility.
        Parameters:
        maxGranularity - the maximum granularity of the log messages.
        fileLogs - the boolean array containing four values.
        terminalLogs - the boolean array containing four values.
      • LogUtil

        public LogUtil​(LogLevel maxGranularity,
                       boolean logToTerminal)
        Constructs the logging utility. Allows the user to specify which outputs are logged to the terminal and which are logged to the file.
        Parameters:
        maxGranularity - the maximum granularity of the log messages.
        logToTerminal - the boolean value indicating if logging to terminal should be enabled.
    • Method Detail

      • setFileLogs

        private void setFileLogs​(boolean[] fileLogs)
        Sets the FileLogs HashMap for selective logging to the file.
        Parameters:
        fileLogs - the boolean array containing four values.
      • setTerminalLogs

        private void setTerminalLogs​(boolean[] terminalLogs)
        Sets the TerminalLogs HashMap for selective terminal logging.
        Parameters:
        terminalLogs - the boolean array containing four values.
      • destroyLogToFile

        public void destroyLogToFile()
        Destroys the Logging to File functionality of the log engine. Sets to false the boolean value indicating that logging to a file is enabled. It also closes the BufferedWriter to free the resource.
      • destroyLogToTerminal

        public void destroyLogToTerminal()
        Destroys the Logging to Terminal functionality of the log engine. Sets to false the boolean value indicating that logging to the terminal is enabled.
      • destroy

        public void destroy()
        Destroys all logging functionality of the log engine. A convenience method that calls both destroyLogToTerminal() and destroyLogToFile().
      • reportProblem

        private void reportProblem​(java.lang.String problem,
                                   java.lang.String solution)
        Used to report problems with the logging engine to the terminal. Reporting is done to the terminal since most likely the BufferedWriter is experiencing an error.
        Parameters:
        problem - the String representing the problem that occurred.
        solution - the String representing the solution the program utilized.
      • log

        private void log​(LogType type,
                         LogLevel granularity,
                         java.lang.String detail)
        Used to log data. Contains the logic for logging both to the terminal and to a file. This method is private so that a user may not pass incorrect LogType objects to the method. Instead, there exist public methods that call this method appropriately.
        Parameters:
        type - the LogType object representing the level of detail for the log.
        granularity - the LogLevel object representing how granular this message is.
        detail - the String representing the data to be logged.
      • logError

        public void logError​(LogLevel level,
                             java.lang.String detail)
        Logs an ERROR message. Used by the user to log error messages. Calls log(LogType, LogLevel, String) for the user.
        Parameters:
        level - the level of granularity of this message.
        detail - the String representing the data to be logged.
      • logInfo

        public void logInfo​(LogLevel level,
                            java.lang.String detail)
        Logs an INFO message. Used by the user to log info messages. Calls log(LogLevel, String) for the user.
        Parameters:
        level - the level of granularity of this message.
        detail - the String representing the data to be logged.
      • logAlgo

        public void logAlgo​(LogLevel level,
                            java.lang.String detail)
        Logs an ALGO message. Used by the user to log algorithm messages. Calls log(LogLevel, String) for the user.
        Parameters:
        level - the level of granularity of this message.
        detail - the String representing the data to be logged.
      • logGraph

        public void logGraph​(LogLevel level,
                             java.lang.String detail)
        Logs a GRPH message. Used by the user to log graph messages. Calls log(LogLevel, String) for the user.
        Parameters:
        level - the level of granularity of this message.
        detail - the String representing the data to be logged.